package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.databinding.DataBindingUtil;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.MapInfoWindowBinding;
import com.sgb.kjwl.model.entity.supplier3.SupplierEntity3;

/**
 * Description:
 * Author zhengkewen
 * Time 2018/8/20
 */
public class MapInfoWindow3 extends LinearLayout {

    protected Context mContext;
    protected MapInfoWindowBinding viewBinding;
    private SupplierEntity3 supplierEntity3;

    public MapInfoWindow3(Context context) {
        this(context, null);
    }

    public MapInfoWindow3(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MapInfoWindow3(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public MapInfoWindow3(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    private void initView() {
        viewBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.map_info_window, this, true);
    }

    public void setData(SupplierEntity3 supplierEntity3) {
        this.supplierEntity3 = supplierEntity3;
        viewBinding.titleView.setText(supplierEntity3.getTitle());
        viewBinding.distanceView.setText(supplierEntity3.getDistance());
        viewBinding.contentView.setText("主营：" + supplierEntity3.getContent());

        RequestOptions options = new RequestOptions()
                .dontAnimate()
                .placeholder(R.drawable.null_img_list)
                .error(R.drawable.null_img_list)
                .centerCrop();
        Glide.with(mContext)
                .load(supplierEntity3.getImgUrl())
                .apply(options)
                .into(viewBinding.imgView);
    }

    public SupplierEntity3 getData() {
        return supplierEntity3;
    }
}
